<!DOCTYPE html>
<html>
<head>
  <title>IOUtils.java</title>
  <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>
  <link rel='stylesheet' type='text/css' href='../../../../../../coverage.css'/>
  <link rel='shortcut icon' type='image/png' href='../../../../../../logo.png'/>
  <script type='text/javascript' src='../../../../../../coverage.js'></script>
  <script type='text/javascript' src='../../../../../../prettify.js'></script>
</head>
<body onload='prettyPrint()'>
  <table cellpadding='0' cellspacing='1'>
    <caption>igraph_client_java/src/main/java/com/taobao/igraph/vipserver/client/utils/IOUtils.java</caption>
    <tr>
      <td class='line'>1</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>package com.taobao.igraph.vipserver.client.utils;</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'></td><td>&nbsp;</td>
      <td><pre class='imports prettyprint' onclick='showHideLines(this)'><div>import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.CharArrayWriter;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.GZIPInputStream;

</div><span>import ...</span></pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>23</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>public class IOUtils {</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>25</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    static public String toString(InputStream input, String encoding) throws IOException {</pre></td>
    </tr>
    <tr>
      <td class='line'>26</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return (null == encoding) ? toString(new InputStreamReader(input))</pre></td>
    </tr>
    <tr>
      <td class='line'>27</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                : toString(new InputStreamReader(input, encoding));</pre></td>
    </tr>
    <tr>
      <td class='line'>28</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>30</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    static public String toString(Reader reader) throws IOException {</pre></td>
    </tr>
    <tr>
      <td class='line'>31</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        CharArrayWriter sw = new CharArrayWriter();</pre></td>
    </tr>
    <tr>
      <td class='line'>32</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        copy(reader, sw);</pre></td>
    </tr>
    <tr>
      <td class='line'>33</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return sw.toString();</pre></td>
    </tr>
    <tr>
      <td class='line'>34</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>36</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    static public long copy(Reader input, Writer output) throws IOException {</pre></td>
    </tr>
    <tr>
      <td class='line'>37</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        char[] buffer = new char[1 &lt;&lt; 12];</pre></td>
    </tr>
    <tr>
      <td class='line'>38</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        long count = 0;</pre></td>
    </tr>
    <tr>
      <td class='line'>39</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        for (int n = 0; (n = input.read(buffer)) >= 0; ) {</pre></td>
    </tr>
    <tr>
      <td class='line'>40</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            output.write(buffer, 0, n);</pre></td>
    </tr>
    <tr>
      <td class='line'>41</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            count += n;</pre></td>
    </tr>
    <tr>
      <td class='line'>42</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>43</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return count;</pre></td>
    </tr>
    <tr>
      <td class='line'>44</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>46</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    static public long copy(InputStream input, OutputStream output) throws IOException {</pre></td>
    </tr>
    <tr>
      <td class='line'>47</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        byte[] buffer = new byte[1024]; // Adjust if you want</pre></td>
    </tr>
    <tr>
      <td class='line'>48</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        int bytesRead;</pre></td>
    </tr>
    <tr>
      <td class='line'>49</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        int totalBytes = 0;</pre></td>
    </tr>
    <tr>
      <td class='line'>50</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        while ((bytesRead = input.read(buffer)) != -1)</pre></td>
    </tr>
    <tr>
      <td class='line'>51</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        {</pre></td>
    </tr>
    <tr>
      <td class='line'>52</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            output.write(buffer, 0, bytesRead);</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>54</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            totalBytes += bytesRead;</pre></td>
    </tr>
    <tr>
      <td class='line'>55</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>57</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return totalBytes;</pre></td>
    </tr>
    <tr>
      <td class='line'>58</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'></td><td>&nbsp;</td>
      <td class='comment' onclick='showHideLines(this)'><div>    /**
     * �������������б?��֤������NULL��
     */</div><span>    /*...*/</span></td>
    </tr>
    <tr>
      <td class='line'>63</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    static public List&lt;String> readLines(Reader input) throws IOException {</pre></td>
    </tr>
    <tr>
      <td class='line'>64</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        BufferedReader reader = toBufferedReader(input);</pre></td>
    </tr>
    <tr>
      <td class='line'>65</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        List&lt;String> list = new ArrayList&lt;String>();</pre></td>
    </tr>
    <tr>
      <td class='line'>66</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        String line = null;</pre></td>
    </tr>
    <tr>
      <td class='line'>67</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        for (; ; ) {</pre></td>
    </tr>
    <tr>
      <td class='line'>68</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            line = reader.readLine();</pre></td>
    </tr>
    <tr>
      <td class='line'>69</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            if (null != line) {</pre></td>
    </tr>
    <tr>
      <td class='line'>70</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                list.add(line);</pre></td>
    </tr>
    <tr>
      <td class='line'>71</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            } else {</pre></td>
    </tr>
    <tr>
      <td class='line'>72</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                break;</pre></td>
    </tr>
    <tr>
      <td class='line'>73</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr>
      <td class='line'>74</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>75</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return list;</pre></td>
    </tr>
    <tr>
      <td class='line'>76</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>78</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    static private BufferedReader toBufferedReader(Reader reader) {</pre></td>
    </tr>
    <tr>
      <td class='line'>79</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(</pre></td>
    </tr>
    <tr>
      <td class='line'>80</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                reader);</pre></td>
    </tr>
    <tr>
      <td class='line'>81</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>84</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    static public void copyFile(String source, String target) throws IOException {</pre></td>
    </tr>
    <tr>
      <td class='line'>85</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        File sf = new File(source);</pre></td>
    </tr>
    <tr>
      <td class='line'>86</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (!sf.exists()) {</pre></td>
    </tr>
    <tr>
      <td class='line'>87</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            throw new IllegalArgumentException("source file does not exist.");</pre></td>
    </tr>
    <tr>
      <td class='line'>88</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>89</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        File tf = new File(target);</pre></td>
    </tr>
    <tr>
      <td class='line'>90</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        tf.getParentFile().mkdirs();</pre></td>
    </tr>
    <tr>
      <td class='line'>91</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (!tf.exists() && !tf.createNewFile()) {</pre></td>
    </tr>
    <tr>
      <td class='line'>92</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            throw new RuntimeException("failed to create target file.");</pre></td>
    </tr>
    <tr>
      <td class='line'>93</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>95</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        FileChannel sc = null;</pre></td>
    </tr>
    <tr>
      <td class='line'>96</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        FileChannel tc = null;</pre></td>
    </tr>
    <tr>
      <td class='line'>97</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        try {</pre></td>
    </tr>
    <tr>
      <td class='line'>98</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            tc = new FileOutputStream(tf).getChannel();</pre></td>
    </tr>
    <tr>
      <td class='line'>99</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            sc = new FileInputStream(sf).getChannel();</pre></td>
    </tr>
    <tr>
      <td class='line'>100</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            sc.transferTo(0, sc.size(), tc);</pre></td>
    </tr>
    <tr>
      <td class='line'>101</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        } finally {</pre></td>
    </tr>
    <tr>
      <td class='line'>102</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            if (null != sc) {</pre></td>
    </tr>
    <tr>
      <td class='line'>103</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                sc.close();</pre></td>
    </tr>
    <tr>
      <td class='line'>104</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr>
      <td class='line'>105</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            if (null != tc) {</pre></td>
    </tr>
    <tr>
      <td class='line'>106</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                tc.close();</pre></td>
    </tr>
    <tr>
      <td class='line'>107</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr>
      <td class='line'>108</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>109</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>111</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public static void delete(File fileOrDir) throws IOException {</pre></td>
    </tr>
    <tr>
      <td class='line'>112</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (fileOrDir == null) {</pre></td>
    </tr>
    <tr>
      <td class='line'>113</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            return;</pre></td>
    </tr>
    <tr>
      <td class='line'>114</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>116</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (fileOrDir.isDirectory()) {</pre></td>
    </tr>
    <tr>
      <td class='line'>117</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            cleanDirectory(fileOrDir);</pre></td>
    </tr>
    <tr>
      <td class='line'>118</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>120</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        fileOrDir.delete();</pre></td>
    </tr>
    <tr>
      <td class='line'>121</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'></td><td>&nbsp;</td>
      <td class='comment' onclick='showHideLines(this)'><div>    /**
     * ����Ŀ¼�µ�����
     */</div><span>    /*...*/</span></td>
    </tr>
    <tr>
      <td class='line'>126</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public static void cleanDirectory(File directory) throws IOException {</pre></td>
    </tr>
    <tr>
      <td class='line'>127</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (!directory.exists()) {</pre></td>
    </tr>
    <tr>
      <td class='line'>128</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            String message = directory + " does not exist";</pre></td>
    </tr>
    <tr>
      <td class='line'>129</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            throw new IllegalArgumentException(message);</pre></td>
    </tr>
    <tr>
      <td class='line'>130</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>132</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (!directory.isDirectory()) {</pre></td>
    </tr>
    <tr>
      <td class='line'>133</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            String message = directory + " is not a directory";</pre></td>
    </tr>
    <tr>
      <td class='line'>134</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            throw new IllegalArgumentException(message);</pre></td>
    </tr>
    <tr>
      <td class='line'>135</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>137</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        File[] files = directory.listFiles();</pre></td>
    </tr>
    <tr>
      <td class='line'>138</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (files == null) {  // null if security restricted</pre></td>
    </tr>
    <tr>
      <td class='line'>139</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            throw new IOException("Failed to list contents of " + directory);</pre></td>
    </tr>
    <tr>
      <td class='line'>140</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>142</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        IOException exception = null;</pre></td>
    </tr>
    <tr>
      <td class='line'>143</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        for (File file : files) {</pre></td>
    </tr>
    <tr>
      <td class='line'>144</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            try {</pre></td>
    </tr>
    <tr>
      <td class='line'>145</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                delete(file);</pre></td>
    </tr>
    <tr>
      <td class='line'>146</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            } catch (IOException ioe) {</pre></td>
    </tr>
    <tr>
      <td class='line'>147</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                exception = ioe;</pre></td>
    </tr>
    <tr>
      <td class='line'>148</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr>
      <td class='line'>149</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>151</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (null != exception) {</pre></td>
    </tr>
    <tr>
      <td class='line'>152</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            throw exception;</pre></td>
    </tr>
    <tr>
      <td class='line'>153</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>154</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>156</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public static void writeStringToFile(File file, String data, String encoding)</pre></td>
    </tr>
    <tr>
      <td class='line'>157</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            throws IOException {</pre></td>
    </tr>
    <tr>
      <td class='line'>158</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        OutputStream os = null;</pre></td>
    </tr>
    <tr>
      <td class='line'>159</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        try {</pre></td>
    </tr>
    <tr>
      <td class='line'>160</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            os = new FileOutputStream(file);</pre></td>
    </tr>
    <tr>
      <td class='line'>161</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            os.write(data.getBytes(encoding));</pre></td>
    </tr>
    <tr>
      <td class='line'>162</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        } finally {</pre></td>
    </tr>
    <tr>
      <td class='line'>163</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            if (null != os) {</pre></td>
    </tr>
    <tr>
      <td class='line'>164</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                os.close();</pre></td>
    </tr>
    <tr>
      <td class='line'>165</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr>
      <td class='line'>166</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>167</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>169</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public static boolean isGzipStream(byte[] bytes) {</pre></td>
    </tr>
    <tr>
      <td class='line'>170</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (bytes == null || bytes.length &lt; 2) {</pre></td>
    </tr>
    <tr>
      <td class='line'>171</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            return false;</pre></td>
    </tr>
    <tr>
      <td class='line'>172</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>174</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return GZIPInputStream.GZIP_MAGIC == ((bytes[1] &lt;&lt; 8 | bytes[0]) & 0xFFFF);</pre></td>
    </tr>
    <tr>
      <td class='line'>175</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'></td><td>&nbsp;</td>
      <td class='comment' onclick='showHideLines(this)'><div>    /*
     * Reads unsigned byte.
     */</div><span>    /*...*/</span></td>
    </tr>
    <tr>
      <td class='line'>180</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private static int readUByte(InputStream in) throws IOException {</pre></td>
    </tr>
    <tr>
      <td class='line'>181</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        int b = in.read();</pre></td>
    </tr>
    <tr>
      <td class='line'>182</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (b == -1) {</pre></td>
    </tr>
    <tr>
      <td class='line'>183</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            throw new EOFException();</pre></td>
    </tr>
    <tr>
      <td class='line'>184</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>185</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (b &lt; -1 || b > 255) {</pre></td>
    </tr>
    <tr>
      <td class='line'>186</td><td>&nbsp;</td>
      <td><pre class='comment'>            // Report on this.in, not argument in; see read{Header, Trailer}.</pre></td>
    </tr>
    <tr>
      <td class='line'>187</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            throw new IOException(".read() returned value out of range -1..255: " + b);</pre></td>
    </tr>
    <tr>
      <td class='line'>188</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>189</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return b;</pre></td>
    </tr>
    <tr>
      <td class='line'>190</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>192</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public static byte[] tryDecompress(byte[] raw) throws Exception {</pre></td>
    </tr>
    <tr>
      <td class='line'>193</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (!isGzipStream(raw)) {</pre></td>
    </tr>
    <tr>
      <td class='line'>194</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            return raw;</pre></td>
    </tr>
    <tr>
      <td class='line'>195</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>197</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        GZIPInputStream gis</pre></td>
    </tr>
    <tr>
      <td class='line'>198</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                = new GZIPInputStream(new ByteArrayInputStream(raw));</pre></td>
    </tr>
    <tr>
      <td class='line'>199</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        ByteArrayOutputStream out</pre></td>
    </tr>
    <tr>
      <td class='line'>200</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                = new ByteArrayOutputStream();</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>202</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        IOUtils.copy(gis, out);</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>204</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return out.toByteArray();</pre></td>
    </tr>
    <tr>
      <td class='line'>205</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr>
      <td class='line'>206</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>}</pre></td>
    </tr>
  </table>
</body>
</html>
